package UILayer;		//makes this class a part of the UILayer package
//import java.io.IOException;
import java.util.Scanner;
import CtrlLayer.*;		//The UILayer needs to know the CtrlLayer

public class MainUI
{
	private PersonCtrl PC;
	private ItemCtrl IC;
	private OrderCtrl OC;
	private CtrlLayer CT;
	
	public MainUI()
	{
		PC = new PersonCtrl();
		IC = new ItemCtrl();
		OC = new OrderCtrl();
		CT = new CtrlLayer();
	}
   
	public void mainMenuStart()
	{
		boolean exit=false;
		loadFromFile();
        while (!exit) //! means while exit not is true (that is: false)
        {
        	int choise = writeMainMenu();
        	switch(choise)
        	{
        		case 1: sale(); break;
        		case 2: rent(); break;
        		case 3: customer(); break;
        		case 4: sale(); break;
        		case 5: rent(); break;
        		case 6: revenue(); break;
        		case 7: supplier(); break;
        		case 8: item(); break;
        		case 9: employee(); break;
        		case 10: pay(); break;
        		case 77: loadFromFile(); break;
        		case 88: saveToFile(); break;
        		case 99: exit = true; break;
        	}//end switch
        }//end while
        saveToFile();
    }//end start
    
	private int writeMainMenu()
    {       
		// creates a keyboard object to read input
		Scanner keyboard = new Scanner(System.in);
		System.out.println("********************");
		System.out.println(CT.getDateString());
		System.out.println(CT.getDateTimeString());
		System.out.println("****  MainMenu  ****");
		System.out.println(" (1)  Kontant Salg");
		System.out.println(" (2)  Udlejning");
		System.out.println(" (3)  Kundekonto");
		System.out.println(" (4)  Salgs Ordre");
		System.out.println(" (5)  Udlejnings Ordre");
		System.out.println(" (6)  Indkomst");
		System.out.println(" (7)  Leverandoer");
		System.out.println(" (8)  Lager");
		System.out.println(" (9)  Medarbejder");
		System.out.println(" (10) Loen");
		System.out.println(" (77) Indlaes data");
		System.out.println(" (88) Gem data");
		System.out.println(" (99) Afslut");
		System.out.print("\n Make your choise: ");
		int choise = keyboard.nextInt();
		return choise;
    }
    
	private void sale() // Salg
	{
		SaleUI UI = new SaleUI();
		UI.SaleMenu();
	}
	private void rent() // Udlejning
	{
		RentUI UI = new RentUI();
		UI.RentMenu();
	}
	private void customer() // kundekonto
	{
		CustomerUI UI = new CustomerUI();
		UI.CustomerMenu();
	}
	
	private void revenue() // Indkomst
	{
		RevenueUI UI = new RevenueUI();
		UI.RevenueMenu();
	}
	private void supplier() // Leverandoer-varer
	{
		SupplierUI UI = new SupplierUI();
		UI.SupplierMenu();
	}
	private void item() // Lager
	{
		ItemUI UI = new ItemUI();
		UI.ItemMenu();
	}
	private void employee() // Medarbejder
	{
		EmployeeUI UI = new EmployeeUI();
		UI.EmployeeMenu();
	}
	private void pay() // Loen
	{
		PayUI UI = new PayUI();
		UI.PayMenu();
	}
	
	private void loadFromFile()
	{
		try
        {
			PC.loadFromFile();
			IC.loadFromFile();
			OC.loadFromFile();
        }
        catch (Exception ex)
        {
            System.out.println(ex);
        }
	}
	   
	private void saveToFile()
	{
		try
        {
			PC.saveToFile();
			IC.saveToFile();
			OC.saveToFile();
        }
        catch (Exception ex)
        {
            System.out.println(ex);
        }
	}
}
